package com.kehutong.applet.service.impl;

import com.kehutong.applet.entity.BusinessCallEntity;
import com.kehutong.applet.service.BusinessCallService;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.orm.Pool;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.orm.jdbc.Page;

import java.util.List;

/**
 * @program: kht
 * @description:
 * @author: joneron
 * @create: 2021/5/26
 **/
public class BusinessCallServiceImpl implements BusinessCallService {

    @Inject
    private JdbcSession jdbcSession;

    @Override
    public Page<BusinessCallEntity> findPage(JSONObject jsonObject) {

        return jdbcSession.findPage(BusinessCallEntity.class)
                .eq("deleted", false)
                .eq(jsonObject,"status")
                .like(jsonObject,"businessTitle")
                .order("createTime", "desc").page(jsonObject).exe();
    }

    @Override
    public List<BusinessCallEntity> findList(JSONObject jsonObject) {
        return jdbcSession.findArray(BusinessCallEntity.class)
                .eq("deleted",false)
                .eq(jsonObject,"businessTitle")
                .exe();
    }

    @Override
    public Integer save(BusinessCallEntity businessCallEntity) {
        return jdbcSession.insert(businessCallEntity);
    }

    @Override
    public Integer update(BusinessCallEntity businessCallEntity) {
        return jdbcSession.updateById(businessCallEntity);
    }

    @Override
    public Integer deleteById(String id) {

        BusinessCallEntity result = Pool.get(BusinessCallEntity.class, id);
        if (result != null) {
            result.setDeleted(true);
            jdbcSession.updateById(result);
        }
        return 1;
    }
}
